#!/bin/env python
#coding=utf-8
'''
author: monkey
mode_code:
1 : in
9 ： out
'''
import __future__
import re,os,sys

net_dev_path = '/proc/net/dev'
mode_code = int(sys.argv[1])
def main():
    with open(net_dev_path,'r') as file:
        data = file.readlines()
    all_net = 0
    for x in data:
      #net_eth = re.findall('eth\d+:\s*\d+(\s+\d+){3}',x)
      net_eth = re.findall('eth\d+:\s*\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+',x)
      #print(net_eth)
      if net_eth:
          net_eth = ''.join(net_eth)
          net_eth = ':'.join(net_eth.split())
          traffic = re.split(':+',net_eth)
          #print(traffic)
          net_mode = traffic[mode_code]
          all_net += int(net_mode)

    return all_net

if __name__ == '__main__':
    code = main()
    print(code)
